package com.xh.xyzp.controller;

import com.xh.xyzp.common.domain.vo.resp.ApiResult;
import com.xh.xyzp.common.domain.vo.resp.PageResp;
import com.xh.xyzp.domain.entity.Notice;
import com.xh.xyzp.domain.vo.NoticePageReq;
import com.xh.xyzp.domain.vo.NoticeSubmitReq;
import com.xh.xyzp.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "公告接口")
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation("详细信息")
    @PostMapping("/info/{noticeId}")
    public ApiResult<Notice> getInfo(@PathVariable("noticeId") Long noticeId) {
        return ApiResult.success(noticeService.getInfo(noticeId));
    }

    @ApiOperation("新增/编辑")
    @PostMapping("/submit")
    public ApiResult<Void> submit(@RequestBody NoticeSubmitReq req) {
        noticeService.submit(req);
        return ApiResult.success();
    }

    @ApiOperation("列表")
    @PostMapping("/list")
    public ApiResult<PageResp<Notice>> getList(@RequestBody NoticePageReq req) {
        return ApiResult.success(noticeService.getList(req));
    }

    @ApiOperation("列表")
    @PostMapping("/admin/list")
    public ApiResult<PageResp<Notice>> getListByAdmin(@RequestBody NoticePageReq req) {
        return ApiResult.success(noticeService.getAdminList(req));
    }

    @ApiOperation("删除公告")
    @PutMapping("/delete/{noticeId}")
    public ApiResult<Void> deleteInfo(@PathVariable("noticeId") Long noticeId) {
        noticeService.deleteInfo(noticeId);
        return ApiResult.success();
    }

} 